import os
import shutil

def movefile_ordered(src_dir, dest_dir, num):
    file_list = os.listdir(src_dir)
    if num > len(file_list):
        print('要移动的文件数量必须小于：', len(file_list))
        exit()

    # 按文件名排序
    file_list.sort()

    for i in range(num):
        filename = file_list[i]
        old_path = os.path.join(src_dir, filename)
        new_path = os.path.join(dest_dir, filename)
        shutil.move(old_path, new_path)
        print('剩余文件：', num - i)

    print('==========任务完成!==========')

if __name__ == "__main__":
    src_dir = 'SN007_20240207_night_light_960_540'
    dest_dir = 'SN007_20240207_night_light_960_540_1'
    if not os.path.exists(dest_dir):
        os.makedirs(dest_dir)

    num_files = len(os.listdir(src_dir))
    movefile_ordered(src_dir, dest_dir, min(num_files, 9000))
